﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CustomControls
{
    public partial class FloatNumberForm : Form
    {
        public int DecimalCount
        {
            get
            {
                return numericUpDown.DecimalPlaces;
            }
            set
            {
                numericUpDown.DecimalPlaces = value;
            }
        }

        public double Value
        {
            set
            {
                numericUpDown.Value = (decimal)value;
            }
            get
            {
                return (double)numericUpDown.Value;
            }
        }

        public double MinValue
        {
            set
            {
                numericUpDown.Minimum = (decimal)value;
            }
            get
            {
                return (double)numericUpDown.Minimum;
            }
        }

        public double MaxValue
        {
            set
            {
                numericUpDown.Maximum = (decimal)value;
            }
            get
            {
                return (double)numericUpDown.Maximum;
            }
        }

        public FloatNumberForm()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter || keyData == Keys.Return)
            {
                btnOk_Click(this, new EventArgs());
            }
            else if (keyData == Keys.Escape)
            {
                btnCancel_Click(this, new EventArgs());
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
        protected override void OnShown(EventArgs e)
        {
            numericUpDown.Select(0, numericUpDown.Value.ToString().Length);
            base.OnShown(e);
        }
    }
}
